//
//  EmoticonViewModel.swift
//  表情键盘
//
//  Created by 晁岳山 on 15/10/24.
//  Copyright © 2015年 晁岳山. All rights reserved.
//

import UIKit
/// 表情包视图模型
class EmoticonViewManager {
    
    static let sharedManager = EmoticonViewManager()
    lazy var packages = [EmoticonPackage]()
    //MARK: - 构造函数
    init() {
        let path = NSBundle.mainBundle().pathForResource("emoticons.plist", ofType: nil, inDirectory: "Emoticons.bundle")!
        let dict = NSDictionary(contentsOfFile: path) as! [String: AnyObject]
        let array = (dict["packages"] as! NSArray).valueForKey("id")
        //添加最近分组
        packages.append(EmoticonPackage(dict: ["group_name_cn": "最近"]))
        //遍历id数组
        for id in array as! [String] {
            loadPlist(id)
        }
    }
    
    //MARK: - 加载每一个plist文件
    private func loadPlist(id: String) {
        let path = NSBundle.mainBundle().pathForResource("info.plist", ofType: nil, inDirectory: "Emoticons.bundle/\(id)")!
        
        let dict = NSDictionary(contentsOfFile: path) as! [String: AnyObject]
        packages.append(EmoticonPackage(dict: dict))
    }
}